class Solution {
    public int[] getLeastNumbers(int[] arr, int k) {
        int len = arr.length;
        if(0 == len || k >= len) {
            return arr;
        }
        holeQuickSort(arr,k,0,len-1);
        return Arrays.copyOf(arr,k);
        
    }
    private void holeQuickSort(int[] arr,int k,int left,int right) {
        if(left<right) {
            int mid = oneHoleQuickSort(arr,left,right);
            if(k == mid) {
                return;
            }else if(k<mid) {
                holeQuickSort(arr,k,left,mid-1);
            }else {
                holeQuickSort(arr,k,mid+1,right);
            }
        }
    }

    private int oneHoleQuickSort(int[] arr,int left,int right) {
        int tem = arr[left];
        while(left<right) {
            while(left<right && arr[right] >= tem) {
                right--;
            }
            arr[left] = arr[right];
            while(left<right && arr[left] <= tem) {
                left++;
            }
            arr[right] = arr[left];
        }
        arr[left] = tem;
        return left;
    }
}